fix <- function(item) {
  return((item * (length(item) - 1) + .5)/length(item))
}

level2num <- function(var) {

  return(as.numeric(paste(var)))
  
}

recoder <- function(item) {
  var <- item
  var[var == -99] <- NA
  var[grep("[A-Za-z]", var)] <- NA
  return(as.character(var))
  
}

recode.01 <- function(item) {
  
  return((item - min(item, na.rm = T))/
           (max(item, na.rm = T) - min(item, na.rm = T)))
  
}

cor.test.plus <- function(x) {
  c(x$estimate, se = unname(sqrt((1 - x$estimate^2)/x$parameter)))
}

plot.coefs <- function(sapply.list, y.title, m.title, lims = c(-1,1)) {
  plot(sapply.list[1,], pch = 20, xaxt = 'n', ylim = lims, ylab = y.title,
       main = m.title, xlab = "")
  sapply(1:ncol(sapply.list), function(x) segments(x, sapply.list[1,x], x, sapply.list[1,x] + sapply.list[2,x]*1.96, lwd=2))
  sapply(1:ncol(sapply.list), function(x) segments(x, sapply.list[1,x], x, sapply.list[1,x] - sapply.list[2,x]*1.96, lwd=2))
  abline(h = 0)
  axis(1, 1:ncol(sapply.list), labels = FALSE)
  text(x = seq(1, ncol(sapply.list), by=1), par("usr")[3] - 0.25*lims[2], labels = label, srt = 45, pos = 1, xpd = TRUE, cex = .6)
}




